package com.example.threadmodel;

import com.example.threadmodel.service.HashThreadManagerService;
import com.example.threadmodel.service.ThreadManagerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;

@Slf4j
@SpringBootApplication
public class ThreadModelApplication implements CommandLineRunner, ApplicationListener<ContextClosedEvent> {

    @Autowired
    private ThreadManagerService threadManagerService;

    @Autowired
    private HashThreadManagerService hashThreadManagerService;

    public static void main(String[] args) {
        SpringApplication.run(ThreadModelApplication.class, args);
    }


    /**
     * 各个模块初始化
     */
    @Override
    public void run(String... args) throws Exception {
        log.info("threadManagerService init");
        threadManagerService.init();

        log.info("HashThreadManagerService init");
        hashThreadManagerService.init();

        log.info("server start success!!!");
    }

    /**
     * 关服
     *
     * @param contextClosedEvent
     */
    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {

    }
}
